package com.hnx.admin.aurora.system.controller;

import com.hnx.admin.aurora.annotation.Log;
import com.hnx.admin.aurora.enums.BusinessType;
import com.hnx.admin.aurora.system.domain.param.dict.form.DictTypeForm;
import com.hnx.admin.aurora.system.domain.param.dict.query.DictQuery;
import com.hnx.admin.aurora.system.service.SysDictTypeService;
import com.hnx.admin.aurora.utils.UUIDUtil;
import com.hnx.admin.aurora.web.json.ResultJson;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
创建人： 倔强的头发
创建时间：2025/6/18
功能描述:

*/
@RestController
@RequestMapping("/system/dict/type")
@RequiredArgsConstructor
public class SysDictTypeController {
    private final SysDictTypeService sysDictTypeService;
    /**
     * 查询字典类型详细
     */
    @PreAuthorize("@auth.hasPermi('system:dict:query')")
    @GetMapping(value = "/{dictId}")
    public ResultJson getInfo(@PathVariable String dictId)
    {
        return sysDictTypeService.getInfo(dictId);
    }
    @PreAuthorize("@auth.hasPermi('system:dict:list')")
    @GetMapping("/list")
    public ResultJson list(DictQuery dictType)
    {
        return  sysDictTypeService.selectDictTypeList(dictType);
    }
    /**
     * 新增字典类型
     */
    @PreAuthorize("@auth.hasPermi('system:dict:add')")
    @Log(title = "字典类型", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultJson add(@Validated @RequestBody DictTypeForm dict)
    {
        dict.setDictId(UUIDUtil.getUUID());
        return sysDictTypeService.insertDictType(dict);
    }
    /**
     * 获取字典选择框列表
     */
    @GetMapping("/optionselect")
    public ResultJson optionselect()
    {
        return sysDictTypeService.selectDictTypeAll();
    }
    /**
     * 删除字典类型
     */
    @PreAuthorize("@auth.hasPermi('system:dict:remove')")
    @Log(title = "字典类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dictIds}")
    public ResultJson remove(@PathVariable String[] dictIds)
    {
        return sysDictTypeService.deleteDictTypeByIds(dictIds);
    }
    /**
     * 修改字典类型
     */
    @PreAuthorize("@auth.hasPermi('system:dict:edit')")
    @Log(title = "字典类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultJson edit(@Validated @RequestBody DictTypeForm dict)
    {
        return sysDictTypeService.updateDictType(dict);
    }
    /**
     * 刷新字典缓存
     */
    @PreAuthorize("@auth.hasPermi('system:dict:remove')")
    @Log(title = "字典类型", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public ResultJson refreshCache()
    {
        return sysDictTypeService.resetDictCache();
    }
}
